#ifndef DWM_CONNECTION_H 
#define DWM_CONNECTION_H 1

#include <boost/asio.hpp>

#include "logging.h"

#include <string>

using boost::asio::ip::tcp;

#define COMMAND_LENGTH 1

class UserConnectionManager; 

//***********************************
class UserConnection : LoggingService
{
  public:
    explicit UserConnection(boost::asio::io_service * io, UserConnectionManager * mgr, const std::string& address);


    void updateUserSocketFrom(const boost::shared_ptr<tcp::socket>& socket);

    void updateUserSocketTo(const boost::shared_ptr<tcp::socket>& socket);

    bool isAuthorized();

    bool isSetup();

    const std::string& getIpAddress();

    std::string toString();

    boost::shared_ptr<tcp::socket>& getUserSocketFrom();
    boost::shared_ptr<tcp::socket>& getUserSocketTo();



  private:

    void listen_command_from();

    void handle_read_command_from(const boost::system::error_code& err);


    bool m_authorized;

//    bool m_setup; 

    std::string m_ip_address;
    

    UserConnectionManager * m_mgr;

    // command socket 
    boost::shared_ptr<tcp::socket>  m_socket_from; // from client
    boost::shared_ptr<tcp::socket>  m_socket_to;

    char m_buffer[1024];

};










#endif
